﻿<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>

<!DOCTYPE html>

<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {

      StringBuilder sb = new StringBuilder();
      sb.AppendLine("<table class=\"tb\"  cellpadding=\"0\" cellspacing=\"0\" border=\"1\">");
      sb.AppendLine("<tr>");
      sb.AppendLine(" <th>選取</th>");
      sb.AppendLine(" <th>代碼</th>");
      sb.AppendLine(" <th>名稱</th>");
      sb.AppendLine("</tr>");
      B2C_MALL_HOME ws = new B2C_MALL_HOME();
      ws.Url = ConfigurationManager.AppSettings["B2C_MALL_HOME"].ToString();
      string strJson = ws.B2C_MALL_B2C_CHARITY_DATA(CommonUtil.GetWebDevice(),
        HttpContext.Current.User.Identity.Name);
      JObject jObj = JsonConvert.DeserializeObject<JObject>(strJson);
      if (jObj["Is_Valid"].ToString() == "Y")
      {
        if (!string.IsNullOrEmpty(jObj["pB2C_CHARITY_DATA_List"].ToString()))
        {
          foreach (var ja in (JArray)jObj["pB2C_CHARITY_DATA_List"])
          {
            sb.AppendLine("<tr>");
            sb.AppendLine(" <td><input type=\"radio\" name=\"rbCode\" onclick=\"ReutrnValue('" + ja["CHARITY_CODE"].ToString() + "')\" /></td>");
            sb.AppendLine(" <td>" + ja["CHARITY_CODE"].ToString() + "</td>");
            sb.AppendLine(" <td>" + ja["CHARITY_NAME"].ToString() + "</td>");
            sb.AppendLine("</tr>");
          }
        }
      }
      //StreamReader sr = new StreamReader(Server.MapPath("CharityCode.txt"), System.Text.Encoding.Default);
      //while (sr.Peek() >= 0)
      //{
      //    string[] strRow = sr.ReadLine().Split(Convert.ToChar(","));
      //    sb.AppendLine("<tr>");
      //    sb.AppendLine(" <td><input type=\"radio\" onclick=\"ReutrnValue('" + strRow[0]+ "')\" /></td>");
      //    sb.AppendLine(" <td>" + strRow[0] + "</td>");
      //    sb.AppendLine(" <td>" + strRow[1] + "</td>");
      //    sb.AppendLine("</tr>");
      //}
      sb.AppendLine("</table>");
      ltlCode.Text = sb.ToString();
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>愛心用戶專碼索引</title>
  <script src="../Scripts/jquery-1.7.1.min.js"></script>
  <style type="text/css">
    .tb {
      border: 1px #333333 solid;
      line-height: 28px;
      border-collapse: collapse;
    }

      .tb th {
        font-size: 12pt;
        font-weight: normal;
        vertical-align: top;
        text-align: center;
        padding: 2px 5px 2px 5px;
        background-color: #EEEEEE;
      }

      .tb td {
        font-size: 12pt;
        padding: 2px 5px 2px 5px;
      }
  </style>
  <script type="text/javascript">
    function ReutrnValue(strCode) {
      //self.opener.document.getElementById('Content_NestedContent_txtCharityCode').value = strCode;
      $("[id*='txtCharityCode']", window.opener.document).val(strCode);
      window.close();
    }
  </script>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <asp:Literal ID="ltlCode" runat="server"></asp:Literal>
    </div>
  </form>
</body>
</html>
